home *** CD-ROM | disk | FTP | other *** search
-
- /*
- * @(#)OID.c 1.2 2/23/90
- */
-
-
- /* Generation of OIDs */
- #include <stdio.h>
- #include "Kernel/h/system.h"
- #include "Kernel/h/mmTypes.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/kmdTypes.h"
-
- extern char *sys_errlist[];
-
- #ifndef NODISK
- extern char NODEDIR[];
- extern char nodisk;
- #endif
-
- /* The compiler has reserved OIDs 0xff000000 - 0xffffffff.
- * And for Cheating Created obj 0xfe000000 - 0xfeffffff.
- *
- * The kernel has reserved OIDs from 0 to 1023 for special purposes,
- * 0 is NULL.
- * 1-1023 so far unassigned.
- * LNN<<24 + 0 is the nodeOID for node LNN.
- */
-
- #define WRITEFREQ 256
-
- static OID nextOID, nextNonReservedOID;
-
- #ifdef NODISK
- #else
- FILE *cpfp;
- FILE *oidfp;
- #define OIDFILENAME "OID"
- char OIDFileName[200];
- extern int errno;
- #endif
-
- /* Do the fsync, but only if DOFSYNC set */
- #define DOFSYNC 0
-
- #ifndef NODISK
- /*ARGSUSED*/
- #endif
- void updateOIDFile(fNextNonReservedOID)
- OID fNextNonReservedOID;
- {
- #ifndef NODISK
- if(!nodisk){
- check(fseek(oidfp, (long) 0, 0));
- fprintf(oidfp, "%08x\n", fNextNonReservedOID);
- if (!DOFSYNC) return;
- (void) fflush(oidfp);
- if ((fsync(fileno(oidfp)) < 0) ) {
- ErrMsg("updateOIDFile: fsync returned %s for file %s\n",
- sys_errlist[errno], OIDFileName);
- }
- }
- #endif
- }
-
- OID getNextOID()
- {
- if ( nextOID >= nextNonReservedOID ){
- nextNonReservedOID += WRITEFREQ;
- updateOIDFile(nextNonReservedOID);
- }
- return (nextOID++);
- }
-
- /* Defines the next OID to use */
- void SetNextOID(fNextOID)
- OID fNextOID;
- {
- nextOID = fNextOID;
- updateOIDFile(nextOID+WRITEFREQ);
- }
-
- /* Initialize the OID allocation stuff */
- void OIDInit()
- {
- #ifndef NODISK
- if(nodisk){
- #endif
- nextOID = (OID) (GetLNN() << 24) | 0x1;
- nextNonReservedOID = nextOID + WRITEFREQ;
- DebugMsg(2, "No OID file, starting OID allocation at: 0x%05x\n", nextOID);
- #ifndef NODISK
- } else {
- (void) sprintf(OIDFileName, "%s/%s", NODEDIR, OIDFILENAME);
- if ( (oidfp = fopen(OIDFileName, "r+")) == (FILE *) NULL) {
- /* No OID file */
- nextOID = (OID) (GetLNN() << 24) | 0x1;
- nextNonReservedOID = nextOID + WRITEFREQ;
- DebugMsg(2, "No OID file, starting OID allocation at: 0x%05x\n", nextOID);
- if ( (oidfp = fopen(OIDFileName, "w+")) == (FILE *) NULL) {
- ErrMsg("Cannot create OID file: %s\n", OIDFileName);
- } else {
- updateOIDFile(nextNonReservedOID);
- }
- } else {
- /* Read in the nextOID */
- if(fscanf(oidfp, "%x", &nextOID) != 1) {
- ErrMsg("Could not read next OID properly from OID file\n");
- nextOID = (OID) (GetLNN() << 24) | 0x1;
- }
- DebugMsg(2, "Next OID to assign: 0x%08x\n", ++nextOID);
- nextNonReservedOID = nextOID+WRITEFREQ;
- updateOIDFile(nextNonReservedOID);
- }
- }
- #endif
- }
-
- /* Set the next NonReserved OID to the nextOID since we do not need
- * any more of them.
- */
- void shutdownOID()
- {
- updateOIDFile(++nextOID);
- #ifdef BSD
- (void) fflush(oidfp);
- if ((fsync(fileno(oidfp)) < 0) ) {
- ErrMsg("OIDInit: fsync returned %s for file %s\n",
- sys_errlist[errno], OIDFileName);
- }
- (void) fclose(oidfp);
- #endif
- }
-